from time import sleep

from common.yaml_opt import YamlTools
from pages.pages import LoginPage
from pages.pages import MainPage
from selenium import webdriver
from common.log import log
import pytest

# @pytest.fixture()
# def get_driver():
#     driver = webdriver.Chrome()
#     driver.maximize_window()
#     sleep(2)
#     driver.get("http://localhost/ranzhi/www")
#     yield driver
#     #后置
#     driver.close()
#     driver.quit()


class Testoa1:
    data=YamlTools.read_yaml_file('aaa.yaml')
    
    # data = [
    #     {'title': '输入正确的用户名和密码,登录成功', 'username': 'admim', 'password': '123456', 'expect': '签退'},
    #     {'title':'输入空的用户名和正确的密码,登录失败','username':'','password':'123456','expect':'登录失败，请检查您的成员名或密码是否填写正确。'},
    #     {'title':'输入16位的用户名和正确的密码,登录失败','username':'1234567890123456','password':'123456','expect':'登录失败，请检查您的成员名或密码是否填写正确。'},
    #     {'title':'输入正确的用户名和空的密码,登录失败','username':'admin','password':'','expect':'登录失败，请检查您的成员名或密码是否填写正确。'}
    # ]
    
    # data = [
    #     {"title": "添加成功", "username": "songld", "realname":"songlb","password": "123459", "repassword": "123459","email":"1233235@qq.com","expect": "禁用成员列表"},
    #     {"title": "两次密码输入有误，添加失败", "username": "lisi", "realname": "李四","password": "1234567", "repassword": "12345678","email": "12314@qq.com", "expect": "保存"},
    #     {"title": "未填写邮箱，添加失败", "username": "wangwu", "realname": "王五", "password": "1234568", "repassword": "1234568","email": "", "expect": "保存"},
    #     {"title": "未填写真名，添加失败", "username": "赵六", "realname": "", "password": "123456","repassword": "123456", "email": "789456@qq.com", "expect": "保存"},
    # ]

    @pytest.mark.parametrize('mydata',data)
    def testlogin(self,get_driver,mydata):
        log.info('开始登录>>>......')
        login=LoginPage(get_driver)
        mp = MainPage(get_driver)
        
        login.type_account(mydata.get('username'))
        login.wait(2)
        login.type_password(mydata.get('password'))
        login.wait(2)
        login.type_submit()
        login.wait(2)
        #获取断言值
        # return login.assert_text()
        
        if mydata.get('expect')=='签退':
            data=mp.assert_text()
            log.info(f"{data},{mydata.get('expect')}")
            assert data == mydata.get('expect')
        else:
            data = LoginPage(get_driver).assert_text()  # 注意添加括号调用方法
            assert data == mydata.get('expect')
            # data = driver.find_element(By.LINK_TEXT, '签退').text
            # assert data == mydata.get('expect')
        # else:
        #     # data = driver.find_element(By.CSS_SELECTOR, '.bootbox-body').text
        #     data=LoginPage(get_driver).assert_text
        #     assert data == mydata.get('expect')
            
            # 修改 testlogin 方法中的调用方式

        
        
        # driver = get_driver
        # sleep(2)
        # driver.find_element(By.ID,'account').send_keys('admim')
        # sleep(2)
        # driver.find_element(By.ID,'password').send_keys('123456')
        # sleep(2)
        # driver.find_element(By.ID,'submit').click()
        # sleep(2)
        # driver.find_element(By.XPATH, '//*[@id="s-menu-superadmin"]/button').click()
        # sleep(2)
        # driver.switch_to.frame('iframe-superadmin')
        # driver.find_element(By.CSS_SELECTOR, '#shortcutBox > div > div:nth-child(1) > div > a > h3').click()
        # sleep(2)
        # driver.find_element(By.ID, "account").send_keys(mydata.get("username"))
        # sleep(2)
        # driver.find_element(By.ID, "realname").send_keys(mydata.get("realname"))
        # sleep(2)
        # driver.find_element(By.ID,'genderf').click()
        # sleep(2)
        # a = driver.find_element(By.ID, "role")
        # a = Select(a)
        # a.select_by_index(13)
        # sleep(2)
        # driver.find_element(By.ID, "password1").send_keys(mydata.get("password"))
        # sleep(2)
        # driver.find_element(By.ID, "password2").send_keys(mydata.get("repassword"))
        # sleep(2)
        # driver.find_element(By.ID, "email").send_keys(mydata.get("email"))
        # sleep(2)
        # driver.find_element(By.ID,'submit').click()
        # sleep(5)
        #
        # if mydata.get("expect") == "禁用成员列表":
        #     data = driver.find_element(By.LINK_TEXT, '禁用成员列表').text
        #     assert data == mydata.get("expect")
        # else:
        #     data = driver.find_element(By.ID, 'submit').text
        #     assert data == mydata.get("expect")


# class TestOA:

#     data1=[
#         {'title':'输入信息成功,可以添加成员','account':'admim','realname':'admim','password1':'123457','password2':'123457','expect':'签退'}
#     ]
#     @pytest.mark.parametrize('mydata', data)
#     def test001(self,get_driver,mydata):
#         driver=get_driver
#         sleep(2)
#         # driver = webdriver.Chrome()
#         # driver.get("http://localhost/ranzhi/www")
#         driver.find_element(By.ID, 'account').send_keys(mydata.get('username'))
#         sleep(2)
#         driver.find_element(By.ID, 'password').send_keys(mydata.get('password'))
#         sleep(2)
#         driver.find_element(By.ID, 'submit').click()
#         sleep(2)



